﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MapRequester : SingletonMonoBehaviour<MapRequester>
{
	public MapModel currentMap { get; private set; }
	public bool isDone { get; private set; }

	protected override void Begin ()
	{
		base.Begin ();
		isDone = false;
	}

	private IEnumerator GenerateMap(string url, int zoom)
	{
		isDone = false;
		currentMap = null;

		WWW www = new WWW(url);
		yield return www;

		if(string.IsNullOrEmpty(www.error))
		{
			currentMap = new MapModel(www, zoom);
			isDone = true;
		}

		www.Dispose();
	}

	private string GenerateBusMarkers(List<BusInformationModel> bus)
	{
		string markers = "";
		if(bus.Count > 0)
		{
			markers = "&markers=color:red|label:B";
			for (int i = 0; i < bus.Count && i < 10; i++) 
			{
				markers += "|" + bus[i].latitude + "," + bus[i].identifier;
			}
		}
		return markers;
	}

	private string BuildPathUrl(float myLatitude, float myLongitute, int zoom, string markers)
	{
		return
			"http://maps.googleapis.com/maps/api/staticmap?" +
				"center=" + myLatitude+","+myLongitute + "&" +
				"zoom=" + zoom + "&" +
				"size=640x640" + "&" +
				"sensor=true" +
				markers;
	}
}
